require("../util.js");
require("../component/components.js");
require("../../jsMt/util.js");
// var userInfo=JSON.parse(sessionStorage.getItem("userInfo"));
// console.log(userInfo.id)
var vm = new Vue({
    el:"#releasePost",
    data:{
        name:"",
        data:{
            loginUid:"",
            circleId:"",
            title:"",
            content:""
        },
        textName:""
    },
    mounted:function(){
        this.searchObject = this.getQueryStringArgs();
        this.data.circleId =this.searchObject&&this.searchObject.circleId;
        this.data.loginUid =this.searchObject&&this.searchObject.uid ;
        this.name=decodeURI(this.searchObject&&this.searchObject.name);
    },
    methods:{
        //后退
        getBack: function () {
            history.go(-1);
        },
        bgimg:function(url){
            url = url?url:"";
            return {
                "background-image":'url("'+url+'"),url("")'
            }
        },
        /*获取查询字符对象*/
        getQueryStringArgs: function () {
            //取得查询字符串并去掉开头的问号
            var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
                args = {},
                items = qs.length ? qs.split("&") : [],
                item = null,
                name = null,
                value = null,
                len = items.length;
            for (var i = 0; i < len; i++) {
                item = items[i].split("=");
                name = item[0];
                value = item[1];
                if (name.length) {
                    args[name] = value;
                }
            }
            return args;
        },
        //发布帖子
        savePost:function(){
            var that=this;
            // var html=$(".ql-editor").find("p").eq(0).text();
            var content =$('#content').getValue();
            that.data.content=content;
            console.log(content);
            if(!that.data.title){
                vm.$refs.prompt.toast("圈子标题不能为空！");
                return;
            }
            if(!content){
                vm.$refs.prompt.toast("圈子内容不能为空！");
                return;
            }
            console.log(that.data)
            this.ajax({url:"/friend/savePost",data:this.data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0){
                    history.go(-1);
                    // that.categoryCarouselList=b.json.data;
                    //console.log(that.categoryCarouselList)
                }else{
                    vm.$refs.prompt.toast("发布帖子失败！")
                }
            });
        },
        // getImage:function(){
        //     console.log("dddddddddd")
        //     this.isNav=2;
        // },
        getNext:function(type){
            var path;
            if(type==1){
                path="/friend/circleMember?circleId="+this.circleId+"&uid="+this.uid+"&isMain="+this.groupInfo.isMain;
            }else if(type==2){
                path="/friend/abstractEdit?circleId="+this.circleId+"&uid="+this.uid;
            }else if(type==3){
                path="/friend/changeChannel";
            }
            location.href=path;
        }
    },
    watch:{
        // textName:function(){
        //     this.data.title=encodeURI(this.textName);
        // }
    }
});
// var formData = new FormData();
// formData.append("loginUid", userInfo.id);
// formData.append("imgSrc", fileInput.files[0]);
$('#content').artEditor({
    imgTar: '#imageUpload',
    limitSize: 5,   // 兆
    showServer: true,
    uploadUrl: host+'/v1/friend/savePostPhoto',
    data: {loginUid:vm.data.loginUid},
    uploadField: 'image',
    breaks: false,
    placeholader: '请输入文章正文内容',
    validHtml: ["<br/>"],
    formInputId: 'target',
    uploadSuccess: function (res) {
        console.log(res)
        // 这里是处理返回数据业务逻辑的地方
        // `res`为服务器返回`status==200`的`response`
        // 如果这里`return <path>`将会以`<img src='path'>`的形式插入到页面
        // 如果发现`res`不符合业务逻辑
        // 比如后台告诉你这张图片不对劲
        // 麻烦返回 `false`
        // 当然如果`showServer==false`
        // 无所谓咯
        // return res;
    },
    uploadError: function (status, error) {
        //这里做上传失败的操作
        //也就是http返回码非200的时候
        alert('网络异常' + status)
    }
});
// var quill=new Quill('#editor-container', {
//     modules: {
//         toolbar: '#toolbar-container'
//     },
//     placeholder: '来吧，尽情发挥吧',
//     theme: 'snow'
// });